import { queryChannel, liveStart, playbackStart } from './service';
const Model = {
  namespace: 'cameraLive',
  state: {
    channelList: [],
  },
  effects: {

    *fetch({ payload }, { call, put }) {
      const response = yield call(queryChannel, payload);
      yield put({
        type: 'queryList',
        payload: Array.isArray(response.data) ? response.data : [],
      });
    },

    *starLive({ payload }, { call, put }) {
      const response = yield call(liveStart,  payload.deviceId,payload.channelId);
      return response;
      // yield put({
      //   type: 'actionStarLive',
      //   payload: response.data,
      // });
    },
    *playbackStart({ payload }, { call, put }) {
      const response = yield call(playbackStart,  payload.deviceId,payload.channelId,payload.startTime,payload.endTime);
      return response;
      // yield put({
      //   type: 'actionStarLive',
      //   payload: response.data,
      // });
    },

  },
  reducers: {
    queryList(state, action) {
      return { ...state, channelList: action.payload };
    },
    actionStarLive(
      state = {
        liveInfo: {},
      },
      action,
    ) {
      return { ...state, liveInfo: action.payload };
    },
  },
};
export default Model;
